import Axios from "axios";
import store from '../index'
// import animates from '../../assets/script/animate'
// import {
//   ARRT_ELEM
// } from '../../assets/script/config'
// import {
//   arrayHas,hexTorgba
// } from "../../assets/script/tool";

let state = {
  pages: [],
  index_page: 0,
  // animates,
  index_elem: {
    old: -1,
    new: -1
  },
  index_attr: {
    old: -1,
    new: -1
  },
  elem_data: {
    old: null,
    new: null
  },
  elem_data_original:{
      old:null,
      new:null
  },
  menu_height: 48,
  attr_height: 110,
  show:1,
  defaultIndex:0,
}

let getters = {
  // 菜单高度
  bottom_gap() {
    // console.log(state.index_attr.new+"state.index_attr.new")
    switch (state.index_attr.new) {
      case -1:
        return state.menu_height
      default:
        return state.menu_height + state.attr_height
    }
  },
  editor_size(state, getters) {
    return {
      default: {
        width: store.state.app.device.width,
        height: store.state.app.device.height - state.menu_height
      },
      active: {
        width: store.state.app.device.width,
        height: store.state.app.device.height - getters.bottom_gap
      }
    }
  },
  scene_size(state, getters) {
    let default_width = getters.editor_size.default.width / getters.editor_size.default.height > store.getters.ratio ? getters.editor_size.default.height * store.getters.ratio : getters.editor_size.default.width
    let active_width = getters.editor_size.active.width / getters.editor_size.active.height > store.getters.ratio ? getters.editor_size.active.height * store.getters.ratio : getters.editor_size.active.width

    return {
      default: {
        width: default_width,
        height: default_width / store.getters.ratio
      },
      active: {
        width: active_width,
        height: active_width / store.getters.ratio
      }
    }
  },
  scale(state, getters) {
    return {
      default: getters.scene_size.default.width / store.state.app.scene.width,
      active: getters.scene_size.active.width / store.state.app.scene.width
    }
  }
}

let mutations = {
  editorSet(state, payload) {
    switch (payload.type) {
      case 'data-pages':
        state.pages = payload.data
        break
    }
  },
}

let actions = {
  async initScene(context) {
    // const res = await Axios.get('http://192.168.2.88:3000/pages')
    // context.commit('editorSet', {
    //   type: 'data-pages',
    //   data: res.data
    // })
  }
}

export default {
  state,
  getters,
  mutations,
  actions
}
